/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Component;

import GameObject.Sprite;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

/**
 *
 * @author Huy
 */
public class MyStateButton extends MyControlItem {

	protected int state;
	protected int nState;

	public MyStateButton(BufferedImage img, int row, int col, int x, int y) {
		nState = col * row;
		sprite = new Sprite(img, col, row, x, y);
		state = 0;
	//	sprite.setScalePosition(true);
	}

	public void setNumberOfState(int n) {
		nState = n;
		if (state > nState) {
			setState(nState - 1);
		}
	}

	public void setState(int st) {
		if(st < 0)
			st += nState;
		state = st % nState;
		((Sprite)sprite).setFrame(state);
	}
	
	public int getState()
	{
		return state;
	}

	@Override
	public boolean mouseReleased(MouseEvent e) {
		if (!super.mouseReleased(e)) {
			return false;
		}
		if (e.getButton() == MouseEvent.BUTTON1) {
			setState(state + 1);
		}
		if (e.getButton() == MouseEvent.BUTTON3) {
			setState(state - 1);
		}
		return true;
	}
}
